package ds.factcom.view.console;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Observable;
import java.util.Observer;

import ds.factcom.controller.MainController;
import ds.factcom.view.console.client.ClientConsoleView;
import ds.factcom.view.console.client.ClientDebtorConsoleView;
import ds.factcom.view.console.invoice.InvoiceConsoleView;
import ds.factcom.view.console.payment.PaymentConsoleView;
import ds.factcom.view.console.product.ProductConsoleView;

/**
 * 
 * @author Javier De Luca, Maximiliano Herrera, Matias Samblancat
 *
 */
//FIXME ver como hacer para limpiar la consola
public class MainMenuConsoleView implements Observer{

	private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
	private boolean end = false;
	private final MainController mainController;
	
	public MainMenuConsoleView(MainController mainController) {
		this.mainController = mainController;
	}

	public void mainMenu(){
		while (!end){
			// Imprimo menu de opciones
			System.out.println("MENU PRINCIPAL DE OPCIONES");
			System.out.println("-------------------------------------------------------");
			System.out.println("1.- Administrar Clientes");
			System.out.println("2.- Administrar Productos");
			System.out.println("3.- Crear Factura");
			System.out.println("4.- Listado de Clientes Deudores");
			System.out.println("5.- Hacer Pagos");
			System.out.println("6.- Salir");
			System.out.println("-------------------------------------------------------");
			System.out.print("Opcion:");
			try {
				
				int s = Integer.valueOf(reader.readLine());

				switch (s) {
				case 1:
					this.adminClient();
					break;
				case 2:
					this.adminProduct();
					break;
				case 3:
					this.createInvoice();
					break;
				case 4:
					this.listClientDebtor();
					break;
				case 5:
					this.makePayment();
					break;	
				case 6:
					this.exit();
					break;
				default:
					System.out.println("Presiono una tacla equivocada");
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	
	private void makePayment() {
		PaymentConsoleView paymentConsoleView = new PaymentConsoleView(this.mainController.getPaymentController());
		paymentConsoleView.GeneratePayment();
	}

	private void exit() {
		System.exit(0);
	}

	private void listClientDebtor() {
		ClientDebtorConsoleView clientDebtorConsoleView = new ClientDebtorConsoleView(this.mainController.getClientController());
		clientDebtorConsoleView.listClientDebtor();
	}

	private void createInvoice() {
		InvoiceConsoleView invoiceConsoleView = new InvoiceConsoleView(this.mainController.getInvoiceController());
		invoiceConsoleView.createInvoice();
	}

	private void adminProduct() {
		ProductConsoleView productConsoleView = new ProductConsoleView(this.mainController.getProductController()); 
		productConsoleView.menuProduct();
	}

	private void adminClient() {
		ClientConsoleView clientConsoleView = new ClientConsoleView(this.mainController.getClientController());
		clientConsoleView.menuClient();
	}

	@Override
	public void update(Observable arg0, Object arg1) {}

}
